// 定义类
class Greeter {
  static staticProperty: number = 123;

  greeting: string;
  
  constructor(message: string) {
    this.greeting = message
  }

  greet() {
    console.log('greet: ', this.greeting)
  }
}
const greeter = new Greeter('WORLD')
console.log('Greeter的实例 greeter：', greeter)


// 使用继承来扩展现有的类
class Animal {
  name: string;
  constructor(theName: string) {
    this.name = theName
  }
  move(distanceInMeters: number = 0) {
    console.log(`${this.name} moved ${distanceInMeters}`)
  }
}
class Snake extends Animal {
  constructor(name: string) {
    super(name)
  }
  move(distanceInMeters = 5) {
    console.log('Slithering...')
    super.move(distanceInMeters)
  }
}
class Horse extends Animal {
  constructor(name) {
    super(name)
  }
  move(distanceInMeters = 30) {
    console.log('Galloping...')
    super.move(distanceInMeters)
  }
}
const snake = new Snake('snake')
const horse = new Horse('horse')
snake.move()
horse.move(100)

// 公共，私有与受保护的修饰符
// 默认成员都是public
class Animal01 {
  public name: string;
  public constructor(theName: string) {
    this.name = theName
  }
  public move(distanceInMeters: number = 5) {
    console.log(`${this.name} moved ${distanceInMeters}m`)
  }
}

// 被标记为 private 时，不能在声明它的类的外部访问
// class Animal02 {
//   private name: string;
//   constructor(theName: string) {
//     this.name = theName
//   }
// }
// const animal02 = new Animal02('lish')
// console.log(animal02.name)

// protected 可以在派生类中被访问
class Person {
  protected name: string;
  constructor(theName: string) {
    this.name = theName
  }
}
class Employee extends Person {
  
}
